package JiHeDemo;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;

/**
 * ArrayList 使用
 *
 * @author 86150
 */
public class ArrrayList1 {
	public static void main(String[] args) {
		ArrayList list = new ArrayList();
		int size = list.size();
		Student s1 = new Student("1111", 1);
		Student s2 = new Student("2222", 2);
		Student s3 = new Student("3333", 3);
		Student s4 = new Student("44444", 4);
		list.add(s1);
		list.add(s2);
		list.add(s3);
		list.add(s4);
		System.out.println("元素个数:" + list.size());
		System.out.println(list.toString());
		//list.remove(s1);//删除s1
		//	list.remove(s1);//删除
		System.out.println("删除之后个数" + list.size());
		Iterator it = list.iterator();
		ListIterator lit = list.listIterator();
		System.out.println("使用迭代器");
		while (it.hasNext()) {
			System.out.println(it.next().toString());
		}
		System.out.println("=====从前往后=====");
		lit = list.listIterator();
		while (lit.hasNext()) {
			System.out.println(lit.nextIndex() + ":" + lit.next());
		}
		System.out.println("使用迭代器=====");

		while (lit.hasPrevious()) {                       //while (lit.hasPrevious()) {
			//System.out.println(lit.previousIndex() + ":" + lit.previous());
			System.out.println(lit.previous());      //}
		}
		while (lit.hasNext()) lit.next();
		System.out.println("=====从后往前====");
		while (lit.hasPrevious()) {
			System.out.println(lit.previousIndex() + ":" + lit.previous());
		}

		System.out.println("=====从前往后=====");
		while (lit.hasNext()) {
			System.out.println(lit.nextIndex() + ":" + lit.next());
		}
		System.out.println("=====从前往后=====");
		lit = list.listIterator();
		while (lit.hasNext()) {
			System.out.println(lit.nextIndex() + ":" + lit.next());
		}
		System.out.println("=====从后往前====");
		while (lit.hasPrevious()) {
			System.out.println(lit.previousIndex() + ":" + lit.previous());
		}
		System.out.println("=====从前往后=====");
		lit = list.listIterator();
		while (lit.hasNext()) {
			System.out.println(lit.nextIndex() + ":" + lit.next());
		}
		System.out.println("=====从后往前====");
		while (lit.hasPrevious()) {
			System.out.println(lit.previousIndex() + ":" + lit.previous());
		}
	}
}
